#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lc (o<<1)
#define rc (o<<1|1)
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=4e4+10;
int n,m,a[MAXN];
LL ans;
struct Seg_T
{
	int f[MAXN<<2][2][2];
	void push_up(int o)
	{
		for(int i=0;i<=1;++i)
			for(int j=0;j<=1;++j)
				f[o][i][j]=max(f[lc][i][0]+max(f[rc][0][j],f[rc][1][j]),f[lc][i][1]+f[rc][0][j]);
		return;
	}
	void build(int o,int l,int r)
	{
		if(l==r)
		{
			f[o][1][1]=a[l];
			return;
		}
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		push_up(o);
		return;
	}
	void update(int o,int l,int r,int k,int x)
	{
		if(l==r)
		{
			f[o][1][1]=x;
			return;
		}
		int mid=(l+r)>>1;
		if(k<=mid)update(lc,l,mid,k,x);
		else update(rc,mid+1,r,k,x);
		push_up(o);
		return;
	}
}T1;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();m=read();
	for(int i=1;i<=n;++i)a[i]=read();
	T1.build(1,1,n);
	while(m--)
	{
		int k=read(),x=read();
		T1.update(1,1,n,k,x);
		ans+=max(max(T1.f[1][0][0],T1.f[1][0][1]),max(T1.f[1][1][0],T1.f[1][1][1]));
	}
	printf("%lld\n",ans);
	return 0;
}
